﻿/*
 *  PassBag is multi-platform software that securely manage/store passwords
 *  Copyright (C) <2009>  <Hugo Rodrigues PEREIRA>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *	
 *  You can find a copy of the GPLv3 at project <root directory>/gpl.txt
 *
 */ 
 

namespace PassBag.Logic {
    /// <summary>
    /// IComparer implementation for <see cref="PasswordObject"/> object.
    /// </summary>
    public class PasswordObjectComparer : System.Collections.Generic.IComparer<PasswordObject> {
        /// <summary>
        /// Comparaison type
        /// </summary>
        public enum ComparisonType {
            /// <summary>
            /// Id
            /// </summary>
            Id = 1,
            /// <summary>
            /// User name
            /// </summary>
            UserName = 2
        }

        private ComparisonType _comparisonType;

        /// <summary>
        /// Gets or sets the comparison method.
        /// </summary>
        /// <value>The comparison method.</value>
        public ComparisonType ComparisonMethod {
            get {
                return _comparisonType;
            }
            set {
                _comparisonType = value;
            }
        }

        #region IComparer<PasswordObject> Members

        /// <summary>
        /// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
        /// </summary>
        /// <param name="x">The first object to compare.</param>
        /// <param name="y">The second object to compare.</param>
        /// <returns>
        /// Value
        /// Condition
        /// Less than zero
        /// <paramref name="x"/> is less than <paramref name="y"/>.
        /// Zero
        /// <paramref name="x"/> equals <paramref name="y"/>.
        /// Greater than zero
        /// <paramref name="x"/> is greater than <paramref name="y"/>.
        /// </returns>
        public int Compare (PasswordObject x, PasswordObject y) {
            PasswordObject p1;
            PasswordObject p2;

            p1 = x;
            p2 = y;

            return p1.CompareTo (p2, _comparisonType);
        }

        #endregion

    }
}
